<template>
	<view class="container">
		<!-- <u-navbar
        class="bg-color navbar"
        title="档案"
        bgColor="#4871c0"
        titleStyle="color:#ffffff"
        leftIconColor="#ffffff"
        @rightClick="rightClick"
        :autoBack="true"
      >
      <view class="u-nav-slot" v-if="!archivesType" slot="right">
        <u-icon
            color="#ffffff"
            name="search"
            size="25"
            @click="searchChange"
        ></u-icon>
      </view>
    </u-navbar> -->
		<view class="header">
			<view class="table ">
				<view @click="archivesChange(0)" :class="archivesType===0?'table-btn active':'table-btn'">
					个人档案
					<view class="active-bb"></view>
				</view>
				<view @click="archivesChange(1)" :class="archivesType===1?'table-btn active':'table-btn'">
					他人档案
					<view class="active-bb"></view>
				</view>
				<view @click="archivesChange(2)" :class="archivesType===2?'table-btn active':'table-btn'">
					教师档案
					<view class="active-bb"></view>
				</view>
			</view>
			<view class="search" v-if="archivesType===1">
				<u-icon color="#000000" name="search" size="25" @click="searchChange"></u-icon>
			</view>
		</view>

		<view v-if="archivesType===0" class="content">
			<archivesView :userInfo='userInfo' v-if="userInfo" ref="archives">
			</archivesView>
			<view v-else class="content-empty">
				<view class="empty">
					<image class="img-empty" src="@/static/empty.png"></image>
				</view>
				<view class="txt mt-20">您还没有添加档案快去添加吧</view>
				<!-- <view class="txt mt-20">您没有查看他人档案的权限哦~</view>  -->
			</view>
		</view>
		<view v-if="archivesType===1" class="content">
			<view class="content-bg">
				<view class="list">
					<view class="list-left position-left">
						<picker class="screen" @change="bindPickerChange" :value="index" range-key="name"
							:range="picker">
							<view class="uni-input">{{picker[index].name}}</view>
						</picker>
					</view>
					<view class="list-right positions">
						<view class="edit-pic ">
							<image class="pic" src="@/static/rt.png"></image>
						</view>
					</view>
				</view>
				<view class="listall" v-if="othersList.length > 0">
					<view class="list" v-for="(item,index) in othersList" :key="index" @click="jumpTo(item.id)">
						<view class="list-left">
							<view class="name"> {{item.name}}</view>
							<view class="user-info">{{item.gender}} {{item.age}}岁</view>
						</view>
						<view class="list-right">
							<view class="txt">
								学部{{item.department}} 学科{{item.subject}}
							</view>
							<view class="edit-pic">
								<image class="pic" src="@/static/rt.png"></image>
							</view>
						</view>
					</view>
				</view>
				<view v-else class="content-empty">
					<view class="empty">
						<image class="img-empty" src="@/static/empty.png"></image>
					</view>
					<!-- <view class="txt">您还没有添加档案快去添加吧</view> -->
					<view class="txt mt-20">您没有查看他人档案的权限哦~</view>
				</view>
			</view>
		</view>
		<view class="content" v-if="archivesType===2">
			<view class="content-bg" v-if="userInfo.is_jiao===1">
				<view class="list-con">
					<view class="list-item" v-for="(item,index) in checkList" :key="index">
						<view class="item-info">
							<view class="item-tile">
								<view class="title">{{item.group_name}}</view>
							</view>
							<view class="u-flex-content">
								<view class="u-flex-title">查看人:</view>
								<view class="item-img-bg" v-for="(item1,i) in item.user_ids_user" :key="i">
									{{strFormat(item1.nickname)}}</view>
								<!-- <view class="item-img" v-for="(item1,i) in item.user_ids_user" :key="i">
									<u--image :src="item1.avatar" shape="circle" width="44rpx" height="44rpx">
									</u--image>
								</view> -->
							</view>
							<view class="u-flex-content">
								<view class="u-flex-title">查看人权限:</view>
								<view class="item-img-bg" v-for="(item1,i) in item.user_auth_ids_user" :key="i">
									{{strFormat(item1.nickname)}}</view>
								<!-- <view class="item-img" v-for="(item1,i) in item.user_auth_ids_user" :key="i">
									<u--image :src="item1.avatar" shape="circle" width="44rpx" height="44rpx">
									</u--image>
								</view> -->
							</view>
						</view>

						<view class="buttons u-flex">
							<view class="button-box button1" @click="deleteCheck(item)">
								删除
							</view>
							<view class="button-box button2" @click="editCheck(item)">
								编辑
							</view>
						</view>
					</view>
				</view>
				<u-button class="save-btn" @click="edit">+创建新组</u-button>
			</view>
			<view v-else class="content-empty">
				<view class="empty">
					<image class="img-empty" src="@/static/empty.png"></image>
				</view>
				<view class="txt mt-20">您没有教师档案设置权限哦~</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		teacherList,
		teacherMe,
		getdepartment,
		checklists,
		checkdel
	} from '@/api/archives.js'
	import archivesView from "../components/archivesView.vue"
	export default {
		data() {
			return {
				archivesType: 0,
				picker: [],
				index: 0,
				selectIndex: "",
				userInfo: {},
				othersList: [],
				checkList: [],
				page: 1, // 页数
				limit: 10, // 一页显示的条数
				total: 0, //总条数
			}
		},
		components: {
			archivesView
		},
		onLoad() {

		},
		onShow() {
			this.getTeacherMe()
			this.getdepartmentFn()
			this.getchecklists();
		},
		onReachBottom() {
			if (this.archivesType === 0) {
				console.log(this.othersList.length)
				if (this.othersList.length < this.total) {
					this.page++
					this.getteacherList(1);
				} else {
					uni.showToast({
						title: '到底了',
						duration: 2000
					});
				}
			} else if (this.archivesType === 2) {
				console.log(this.checkList.length)
				if (this.checkList.length < this.total) {
					this.page++
					this.getchecklists(1);
				} else {
					uni.showToast({
						title: '到底了',
						duration: 2000
					});
				}
			}
		},
		methods: {
			strFormat(str) {
				if (str.length > 3) {
					return str.substring(0, 3) + '...';
				} else {
					return str
				}
			},
			getdepartmentFn() {
				getdepartment({}).then(res => {
					if (res.code > 0) {
						this.picker = res.data.data
					}
				})
			},
			getteacherList(type) {
				teacherList({
					department_id: this.selectIndex,
					limit: this.limit,
					page: this.page,
				}).then(res => {
					if (res.code > 0) {
						if (type == 1) {
							this.total = res.data.total
							this.othersList.push(...res.data.data)
						} else {
							this.othersList = res.data.data
							this.total = res.data.total
						}
					}
				})
			},
			getTeacherMe() {
				teacherMe({}).then(res => {
					if (res.code > 0) {
						this.userInfo = res.data
					}
				})
			},
			getchecklists(type) {
				checklists({
					limit: this.limit,
					page: this.page,
				}).then(res => {
					if (res.code > 0) {
						if (type == 1) {
							this.total = res.data.total
							this.checkList.push(...res.data.data)
						} else {
							this.checkList = res.data.data
							this.total = res.data.total
						}
					}
				})
			},
			rightClick() {},
			archivesChange(data) {
				this.page = 1
				this.total = 0
				this.archivesType = data
				if (this.archivesType === 0) {
					this.getTeacherMe()
				} else if (this.archivesType === 1) {
					this.getteacherList()
				} else if (this.archivesType === 2) {
					this.getchecklists()
				}
			},
			jumpTo(id) {
				uni.navigateTo({
					url: "/pages/archives/index/details?id=" + id + "&type=2",
				})
			},
			bindPickerChange(e) {
				this.index = e.detail.value
				this.selectIndex = this.picker[this.index].department_id
				console.log(e.detail.value, this.selectIndex)
				this.getteacherList()

			},
			searchChange() {
				// this.isSearch = true
				uni.navigateTo({
					url: "/pages/archives/index/search",
				})
			},
			deleteCheck(data) {
				checkdel({
					id: data.id
				}).then(res => {
					if (res.code > 0) {
						this.$toast('删除成功');
						this.getchecklists()
					}
				})
			},
			editCheck(data) {
				uni.navigateTo({
					url: "/pages/archives/teacherFiles/edit?id=" + data.id
				})
			},
			edit() {
				uni.navigateTo({
					url: "/pages/archives/teacherFiles/edit",
				})
			}
		}
	}
</script>

<style lang="less">
	.u-flex {
		display: flex
	}

	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.header {
			width: 100%;
			display: flex;
			//  justify-content:space-around;
			align-items: flex-end;

			.table {
				width: 90%;
				padding: 20rpx;
				display: flex;
				justify-content: flex-start;
				align-items: flex-end;
				box-sizing: border-box;
			}

			.search {
				width: 10%;
				padding-bottom: 20rpx;
			}
		}

		.content {
			width: 100%;
			min-height: calc(100vh - 182rpx);
			background: #f8f8f8;

			.content-bg {
				width: 100%;
				box-sizing: border-box;
				padding: 20rpx 30rpx;
				box-sizing: border-box;
				background: #f8f8f8;

				.list {
					width: 100%;
					background: #ffffff;
					padding: 30rpx 20rpx;
					box-sizing: border-box;
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-radius: 10rpx;
					margin-top: 20rpx;
					position: relative;

					.list-left {
						display: flex;
						align-items: flex-end;
						font-size: 25rpx;
						color: #939393;

						.name {
							font-size: 28rpx;
							font-weight: bold;
							color: #353437;
							margin-right: 20rpx;
						}

						.user-info {
							font-size: 26rpx;
							color: #939393;
						}
					}

					.list-right {
						display: flex;
						font-size: 25rpx;
						color: #939393;

						.edit-pic {
							width: 40rpx;
							height: 40rpx;

							.pic {
								width: 100%;
								height: 100%;
							}
						}
					}
				}

				.list-con {
					.list-item {
						padding: 30rpx 24rpx 30rpx 20rpx;
						background-color: #fff;
						border-radius: 16rpx;
						margin-bottom: 20rpx;

						.item-info {
							margin-left: 10rpx;

							.item-tile .title {
								color: #333333;
								font-size: 32rpx;
								line-height: 88rpx
							}

							.u-flex-content {
								margin-bottom: 20rpx;
								line-height: 32rpx;
								display: flex;
								align-items: center;
								flex-wrap: wrap;

								.u-flex-title {
									color: #666666;
									font-size: 28rpx;
									margin-right: 20rpx;
								}

								.item-img-bg {
									margin-right: 10rpx;
									width: 64rpx;
									height: 64rpx;
									border-radius: 50%;
									background-color: #4871C0;
									color: #ffffff;
									font-size: 20rpx;
									text-align: center;
									line-height: 64rpx;
								}

							}
						}


						.button-box {
							width: 128rpx;
							height: 64rpx;
							line-height: 64rpx;
							text-align: center;
							border-radius: 16rpx;
							opacity: 1;
							font-size: 28rpx;
							font-weight: 500;
							margin-top: 20rpx;
						}

						.button1 {
							color: #4871C0;
							border: 1px solid #4871C0;
							margin-left: auto;
						}

						.button2 {
							color: #FFFFFF;
							background: #4871C0;
							margin-left: 20rpx;
						}
					}
				}
			}

		}

		.table-btn {
			color: #cfd2d5;
			font-size: 24rpx;
			margin-right: 20rpx;
			line-height: 50rpx;
		}

		.active {
			color: #4871c0;
			font-size: 30rpx;
			font-weight: bold;

			// border-bottom: 2px solid #4871c0;
			// box-sizing: border-box;
			.active-bb {
				margin: 0 auto;
				width: 60rpx;
				border-bottom: 2px solid #4871c0;
			}
		}

		.content-empty {
			margin: 0 auto;

			.empty {
				margin: 200rpx auto 10rpx;
				width: 200rpx;
				height: 180rpx;

				.img-empty {
					width: 100%;
					height: 100%;
				}
			}

			.txt {
				color: #636871;
				text-align: center;
			}
		}
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.screen {
		width: 670rpx;
		min-height: 50rpx;
		// background: red;
		// background: red;
	}

	.positions {
		position: absolute;
		top: 10rpx;
		right: 20rpx;
		z-index: 0;
	}

	.position-left {
		position: absolute;
		top: 10rpx;
		left: 20rpx;
		z-index: 10;
	}

	.mt-88 {
		margin-top: 88rpx;
	}

	.mt-20 {
		margin-top: 40rpx;
	}

	.navbar {
		width: 100%;
	}

	.search {}

	.save-btn {
		border: 1px solid #4871C0;
		background: #F8F8F8;
		color: #4871C0;
		font-size: 32rpx;
		position: fixed;
		bottom: 30rpx;
		left: 24rpx;
		right: 24rpx;
		width: calc(100% - 48rpx);
	}
</style>
